CODAfrica <- read_excel("../Cause of Death AFRICA.xlsx")
if (!all(c("Entity", "Year") %in% names(CODAfrica))) {
stop("Expected columns 'Entity' and 'Year' not found in Cause of Death AFRICA.xlsx")
}
top10 <- CODAfrica %>%
filter(Entity == "South Africa", Year == 2006) %>%
select(-Entity, -Code, -Year) %>%
pivot_longer(cols = everything(), names_to = "Cause", values_to = "Fatalities") %>%
arrange(desc(Fatalities)) %>%
slice_head(n = 10) %>%
mutate(Group = if_else(Cause == "HIV/AIDS fatalities", "HIV/AIDS", "Other causes"),
Color = if_else(Group == "HIV/AIDS", "red", "grey"))
p <- ggplot(top10, aes(x = reorder(Cause, Fatalities), y = Fatalities, fill = Group)) +
geom_col(color = "black", width = 0.7) +
scale_fill_manual(values = c("HIV/AIDS" = "red", "Other causes" = "grey")) +
coord_flip() +
labs(title = "Top 10 Causes of Death in South Africa (2006)",
x = NULL, y = "Number of Fatalities", fill = "Cause of Death") +
theme_minimal() +
theme(axis.text.y = element_text(size = 14)) +
scale_y_continuous(labels = label_comma())
ggplotly(p)
The number of fatalities due to HIV/AIDS in South Africa in 2006 are almost 4 times the second highest cause of death, which is Cardiovascular Disease.